package edu.xidian.bdilab.jrbigdata.service.admin.governmentadmin.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.xidian.bdilab.jrbigdata.controller.admin.AdminCode;
import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;

import edu.xidian.bdilab.jrbigdata.domain.GovernmentUser;
import edu.xidian.bdilab.jrbigdata.mapper.GovermentUserMapper;
import edu.xidian.bdilab.jrbigdata.service.admin.governmentadmin.governmentadminService;
import org.springframework.beans.factory.annotation.Autowired;
import edu.xidian.bdilab.jrbigdata.mapper.GovernmentInfoMapper;
import  edu.xidian.bdilab.jrbigdata.domain.GovernmentInfo;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.List;
@Service
public class governmentadminServiceimpl implements governmentadminService{

    @Autowired
   GovernmentInfoMapper governmentInfoMapper;
    @Autowired
    GovermentUserMapper govermentUserMapper;

    @Override
    public ResponseResult governmentManage_check() throws Exception
    {
        ResponseResult responseResult=new ResponseResult();
        try{
            List<GovernmentInfo> government=governmentInfoMapper.selectList(null);
            if(government.size()!=0)
            {
                responseResult.setData(government);
                responseResult.setSuccess(Boolean.TRUE);
                responseResult.setCode(AdminCode.SelectSUCCESS.getCode());
                responseResult.setMessage(AdminCode.SelectSUCCESS.getMessage());
            }
            else
            {
                responseResult.setSuccess(Boolean.TRUE);
                responseResult.setCode(AdminCode.NOT_EXIST.getCode());
                responseResult.setMessage(AdminCode.NOT_EXIST.getMessage());
            }
            return responseResult;
        }catch (Exception e){
            responseResult.setSuccess(Boolean.FALSE);
            responseResult.setCode(AdminCode.SelectFailed.getCode());
            responseResult.setMessage(AdminCode.SelectFailed.getMessage());
            return responseResult;
        }
    }
    @Override
    public ResponseResult  governmentManage_delete(String userName)throws Exception
    {

        ResponseResult responseResult=new ResponseResult();
        try{
            QueryWrapper<GovernmentInfo> governmentInfoQueryWrapper=new QueryWrapper<>();
            governmentInfoQueryWrapper.eq("fk_user_name",userName);
            governmentInfoMapper.delete(governmentInfoQueryWrapper);
            QueryWrapper<GovernmentUser> governmentUserQueryWrapper=new QueryWrapper<>();
            governmentUserQueryWrapper.eq("user_name",userName);
            govermentUserMapper.delete(governmentUserQueryWrapper);
            responseResult.setSuccess(Boolean.TRUE);
            responseResult.setCode(AdminCode.DELEATESUCCESS.getCode());
            responseResult.setMessage(AdminCode.DELEATESUCCESS.getMessage());
            return responseResult;
        }catch (Exception e){
            responseResult.setSuccess(Boolean.FALSE);
            responseResult.setCode(AdminCode.DELEATEFAILED.getCode());
            responseResult.setMessage(AdminCode.DELEATEFAILED.getMessage());
            return responseResult;
        }
    }
}
